$OpenBSD: patch-Makefile,v 1.6 2015/03/31 18:29:51 pascal Exp $
$RuOBSD: patch-Makefile,v 1.3 2009/02/07 10:28:03 form Exp $
--- Makefile.orig	Sun Jan 23 19:11:04 2011
+++ Makefile	Tue Mar 31 17:06:38 2015
@@ -6,33 +6,47 @@
 #
 # Path for the floppy disk device
 #
-FDISK=/dev/fd0
+FDISK=/dev/fd0c
 
 AS=as -32
-CC=gcc
+CC?=gcc
 
-CFLAGS= -Wall -march=i486 -m32 -O2 -fomit-frame-pointer -fno-builtin -ffreestanding -fPIC -fno-stack-protector
+CFLAGS+= -Wall -march=i486 -m32 -O2 -fomit-frame-pointer -fno-builtin -ffreestanding -fPIC -fno-stack-protector -fno-pie
 
-OBJS= head.o reloc.o main.o test.o init.o lib.o patn.o screen_buffer.o \
+OBJS= head.o reloc.o main.o test.o init.o patn.o screen_buffer.o \
       config.o linuxbios.o memsize.o pci.o controller.o random.o spd.o \
       error.o dmi.o cpuid.o
 
-all: memtest.bin memtest
+all: memtest.bin memtest_s.bin memtest memtest_s
 
 # Link it statically once so I know I don't have undefined
 # symbols and then link it dynamically so I have full
 # relocation information
-memtest_shared: $(OBJS) memtest_shared.lds Makefile
-	$(LD) --warn-constructors --warn-common -static -T memtest_shared.lds \
-	-o $@ $(OBJS) && \
-	$(LD) -shared -Bsymbolic -T memtest_shared.lds -o $@ $(OBJS)
+memtest_shared: $(OBJS) lib.o memtest_shared.lds Makefile
+	$(LD) --warn-constructors --warn-common -static -nopie \
+	-T memtest_shared.lds -o $@ $(OBJS) lib.o && \
+	$(LD) -shared -Bsymbolic -T memtest_shared.lds -o $@ $(OBJS) lib.o
 
+memtest_shared_s: $(OBJS) lib_s.o memtest_shared.lds Makefile
+	$(LD) --warn-constructors --warn-common -static -nopie \
+	-T memtest_shared.lds -o $@ $(OBJS) lib.o && \
+	$(LD) -shared -Bsymbolic -T memtest_shared.lds -o $@ $(OBJS) lib_s.o
+
 memtest_shared.bin: memtest_shared
 	objcopy -O binary $< memtest_shared.bin
 
+memtest_shared_s.bin: memtest_shared_s
+	objcopy -O binary $< memtest_shared_s.bin
+
 memtest: memtest_shared.bin memtest.lds
 	$(LD) -s -T memtest.lds -b binary memtest_shared.bin -o $@
 
+memtest_s: memtest_shared_s.bin memtest.lds
+	$(LD) -s -T memtest.lds -b binary memtest_shared_s.bin -o $@
+
+lib_s.o: lib.c
+	$(CC) -c $(CFLAGS) -DSERIAL_CONSOLE_DEFAULT=1 $< -o $@
+
 head.s: head.S config.h defs.h test.h
 	$(CC) -E -traditional $< -o $@
 
@@ -46,11 +60,15 @@ memtest.bin: memtest_shared.bin bootsect.o setup.o mem
 	$(LD) -T memtest.bin.lds bootsect.o setup.o -b binary \
 	memtest_shared.bin -o memtest.bin
 
+memtest_s.bin: memtest_shared_s.bin bootsect.o setup.o memtest.bin.lds
+	$(LD) -T memtest.bin.lds bootsect.o setup.o -b binary \
+	memtest_shared_s.bin -o memtest_s.bin
+
 reloc.o: reloc.c
 	$(CC) -c $(CFLAGS) -fno-strict-aliasing reloc.c
 
 test.o: test.c
-	$(CC) -c -Wall -march=i486 -m32 -Os -fomit-frame-pointer -fno-builtin -ffreestanding test.c
+	$(CC) -c -Wall -march=i486 -m32 -Os -fomit-frame-pointer -fno-builtin -ffreestanding -fno-pie test.c
 
 clean:
 	rm -f *.o *.s *.iso memtest.bin memtest memtest_shared memtest_shared.bin
